package com.corelibs.corelibsdemo

import androidx.lifecycle.viewModelScope
import com.corelibs.corelibsdemo.api.UserApi
import com.lib.core.base.BaseViewModel
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch

class TestViewModel : BaseViewModel() {

    private val userApi: UserApi by lazy {
        getApi(UserApi::class.java)
    }


    fun changeText(callback: (text: String) -> Unit) {
        viewModelScope.launch {
            delay(3000)  // 挂起，不会阻塞主线程
            callback("3秒后改变的文本")
        }
    }

    fun postLogin() {
        launch({
            userApi.postLogin(mutableMapOf())
        }, success = {

        })
    }
}